
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVo getById(Long id) {
        User user = userMapper.getuserById(id);
        return BeanUtil.toBean(user, UserVo.class);
    }

    @Override
    //xujiacheng交的作业
    public UserVo login(UserDto userDto) {
        User user = userMapper.getuserByUserName(userDto.getUserName());
        if(user == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"用户名不存在");
        }
        String encryptPassword = DigestUtils.md5DigestAsHex((SALT + userDto.getPassword()).getBytes());
        if(!user.getPassword().equals(encryptPassword)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"密码错误");
        }
    }

    @Override
    public int deleteUser(Long id) {
        return userMapper.deleteById(id);
    }



}
